// -----------------------------以下绑定状态和类型下拉框的值-------------------------------------------------
$.get("/typelist")
    .done(list=>{
        list.forEach(function (Sertype) {
            var opt= $("<option/>");
            opt.val(Sertype.serviceId);
            opt.text(Sertype.serviceNames);
            opt.appendTo("#queryForm [name=fuwuid]");
        })
    });
$.get("/startlist")
    .done(list=>{
        list.forEach(function (start) {
            var opt= $("<option/>");
            opt.val(start.fuwuid);
            opt.text(start.fuwuleixing);
            opt.appendTo("#queryForm [name=serviceId]");
        })
    });

// -----------------------------------------以下是条件查询---------------------------------------------------
function chaxun() {
    var formParams=$("#queryForm").serialize();
    var obj=Qs.parse(formParams);
    $("#serTb").bootstrapTable("refresh",{query:obj});

}
// -----------------------------------------以下是修改--------------------------------------------------
$.get("/typelist")
    .done(list=>{
        list.forEach(function (Sertype) {
            var opt= $("<option/>");
            opt.val(Sertype.serviceId);
            opt.text(Sertype.serviceNames);
            opt.appendTo("#update [name=serviceType]");
        })
    });
function xiugai() {
    var arr = $("#serTb").bootstrapTable("getSelections");
    if(arr[0].fuwustart.fuwuleixing=="已归档"||arr[0].fuwustart.fuwuleixing=="已提交"){
        toastr.success("此记录已归档或已提交不可修改！");
        return
    }
    if (arr.length == 0) {
        swal({
            type: "warning",
            title: "友情提示！",
            text: "请选择一项待修改！",
            confirmButtonText: "确定"
        });
        return;
    }
    $("#update [name=serviceId]").val(arr[0].serviceId)
    $("#update [name=serviceName]").val(arr[0].serviceName);
    $("#update [name=cellphone]").val(arr[0].customer.cellphone);
    $("#update [name=name]").val(arr[0].customer.name);
    $("#update [name=serviceType]").val(arr[0].servicetype.serviceId);
    $("#update [name=serContent]").val(arr[0].serviceContent);
    $("#update [name=beizhu]").val(arr[0].note);
    $("#update").dialog("show");
}

$("#update").dialog({
    title:"修改服务",
    btnBind(){
        var params=$("#update form").serialize();
        $.get(`${ctx}/serupdate`,params)
            .done(msg=>{
                toastr.success(msg);
                $("#serTb").bootstrapTable("refresh");
                $("#update").dialog("hide");
            });
    }
})
// -----------------------------------------以下是删除功能--------------------------------------------------
function delser() {
    var arr=$("#serTb").bootstrapTable("getSelections");
    if(arr[0].fuwustart.fuwuleixing=="已归档"||arr[0].fuwustart.fuwuleixing=="已提交"){
        toastr.success("此记录已归档或已提交不可删除！");
        return
    }
    if(arr.length==0){
        swal({
           type:"warning",
            title:"信息提示！！",
            text:"请选择一项待删除！",
            confirmButtonText: "确定"
        });
        return;
    }
    var ids=arr.map(Service=>{
        return "ids="+Service.serviceId
    }).join("&");
    $.get("delService?"+ids,msg=>{
        var ids = confirm("Are you sure to delete the current data?");
        if(!ids){
            return false;
        }
        toastr.warning(msg);
        $("#serTb").bootstrapTable("refresh");
    })
}
// -----------------------------------------以下是提交功能--------------------------------------------------
function tijiao() {
    var arr=$("#serTb").bootstrapTable("getSelections");
    if(arr.length==0){
        swal({
            type:"warning",
            title:"信息提示！！",
            text:"请选择一项待提交！",
            confirmButtonText: "确定"
        });
        return;
    }
    var i=arr.map(Service=>{
        return "i="+Service.serviceId
    })
    $.get("xiugaiSta?"+i,msg=>{
        toastr.warning(msg);
        $("#serTb").bootstrapTable("refresh");
    })
}
// -----------------------------------------以下是添加功能--------------------------------------------------
$.get("/susNamelist")
    .done(list=>{
        list.forEach(function (cusname) {
            var opt= $("<option/>");
            opt.val(cusname.customerId);
            opt.text(cusname.name);
            opt.appendTo("#addser [name=serviceCustomer]");
        })
    });
$.get("/staYglist")
    .done(list=>{
        list.forEach(function (stayg) {
            var opt= $("<option/>");
            opt.val(stayg.empId);
            opt.text(stayg.empName);
            opt.appendTo("#addser [name=operateMan]");
        })
    });
$.get("/staYglist")
    .done(list=>{
        list.forEach(function (stayg) {
            var opt= $("<option/>");
            opt.val(stayg.empId);
            opt.text(stayg.empName);
            opt.appendTo("#addser [name=processedMan]");
        })
    });
$.get("/typelist")
    .done(list=>{
        list.forEach(function (Sertype) {
            var opt= $("<option/>");
            opt.val(Sertype.serviceId);
            opt.text(Sertype.serviceNames);
            opt.appendTo("#addser [name=serviceType]");
        })
    });
$.get("/startlist")
    .done(list=>{
        list.forEach(function (start) {
            var opt= $("<option/>");
            opt.val(start.fuwuid);
            opt.text(start.fuwuleixing);
            opt.appendTo("#addser [name=status]");
        })
    });
function add() {
    $("#addser").dialog("show");
}
$("#addser").dialog({
    title:"添加服务",
    btnBind(){
        var params=$("#addser form").serialize();
        $.get(`${ctx}/addser`,params)
            .done(msg=>{
                toastr.success(msg);
                $("#serTb").bootstrapTable("refresh");
                $("#addser").dialog("hide");
            });
    }
})

// --------------------------------------查看详情--------------------------------------------------------------
$.get("/typelist")
    .done(list=>{
        list.forEach(function (Sertype) {
            var opt= $("<option/>");
            opt.val(Sertype.serviceId);
            opt.text(Sertype.serviceNames);
            opt.appendTo("#See [name=leixing]");
        })
    });
$("#See").dialog({
    title:"查看服务详情",
    size:"modal-lg",
})
function chakan() {
    var arr=$("#serTb").bootstrapTable("getSelections");
    if(arr.length==0){
        swal({
            type:"warning",
            title:"信息提示！！",
            text:"选择您要查看的内容！",
            confirmButtonText: "确定"
        });
        return;
    }
    $("#See [name=name]").val(arr[0].serviceName);
    $("#See [name=kehu]").val(arr[0].customer.name);
    $("#See [name=leixing]").val(arr[0].servicetype.serviceId);
    $("#See [name=phone]").val(arr[0].customer.cellphone);
    $("#See [name=neirong]").val(arr[0].serviceContent);
    $("#See [name=beizhu]").val(arr[0].note);
    $("#See").dialog("show");
}